import type { TipsWxVo } from "@/api/tips"

export interface goOption {
	name: string | null,
	value: any | null,
	close: boolean | null,
}

interface vneue {
	id: number,
	description: string,
	history: string,
	file:ossFile[]
}

interface ossFile {
	url: string,
	fileType: string
}

export const goIndex = () => {
	return go("pages/index/index",null)
}

export const goHanfuDe = async (id: string) => {
	const r = await uni.setStorage({
		key: "hanfuId",
		data: id
	})
	return await go("pages/hanfuDe/hanfuDe", {
		name: "id",
		value: id,
		close: true
	})
}
// 跳转到汉服列表页面
export const goHanfuList = () => {
	return go("pages/hanfuList/index", null)
}

export const goPackage = () => {
	return go("pages/package/package", null)
}

export const goPackageDe = async (id:string) => {
	const r = await uni.setStorage({
		key: "packageId",
		data: id
	})
	return go("pages/packageDe/packageDe", {
		name: "id",
		value: id,
		close: true
	})
}

export const goActvieList = () => {
	return go("pages/activeList/activeList", null)
}

export const goActviceDe = async (id:string) => {
	const r = await uni.setStorage({
		key: "activeId",
		data: id
	})
	return go("pages/activeDe/activeDe", {
		name: "id",
		value: "",
		close: true
	})
}

export const goSample = () => {
	return go("pages/Sample/Sample", null)
}

export const goPhoto = async (id:string) => {
	const r = await uni.setStorage({
		key: "photoId",
		data: id
	})
	return go("pages/photo/photo", {
		name: "id",
		value: id,
		close: true
	})
}

export const goTips = () => {
	return go("pages/tips/tips", null)
}

export const goTipsDe = async (data :TipsWxVo) => {
	const r = await uni.setStorage({
		key: "tipsDe",
		data: data
	})
	return go("pages/tipsDe/tipsDe", {
		name: "id",
		value: data.id,
		close: true
	})
}


export const goVenue = () => {
	return go("pages/veune/veune", null)
}

export const goVenueItem = async (data: vneue) => {
	const r = await uni.setStorage({
		key: "vneue",
		data: data
	})
	return go("pages/vneueDe/vneueDe", {
		name: "id",
		value: "",
		close: true
	})
}

// 跳转关于我的页面
export const goMy = ()=>{
	return go("pages/my/my",null)
}


// 返回上一级
export const goBack = () => {
	return uni.navigateBack()
}


// 实现跳转的方法  path为路径
const go = (path: string, query:goOption | null) => {
	
	if (query != null) {
		path = `${path}?${query.name}=${query.value}`
	}

	if (query?.close) {
		return uni.navigateTo({
			url: `../../${path}`,
		})
	}

	return uni.redirectTo({
		url: `../../${path}`,
	})
	
}